//
//  HomeOrderTableViewCell.m
//  Doctors
//
//  Created by 王森 on 16/4/8.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "HomeOrderTableViewCell.h"

@implementation HomeOrderTableViewCell
{
    
    
    NSString *_orderId;
    NSString *_status;
    NSString *_mobileNumber;

}
- (void)awakeFromNib {
    // Initialization code
}
- (IBAction)boDaMobile:(id)sender {
    
    if (_boDaMobile) {
        _boDaMobile(_mobileNumber);
        
    }
    
}

-(void)cellFuzhi:(NSDictionary *)dicRecource
{
    
    /*服务时间*/
    
    NSString *time_string = dicRecource[@"orderInfo"][@"time"];
    NSTimeInterval _interval=[time_string doubleValue] / 1000.0;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
    NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
    [objDateformat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
    NSString *day_date =[objDateformat stringFromDate: date];
    NSLog(@"订单时间%@", day_date);
    
    self.name.text= dicRecource[@"orderInfo"][@"username"];
    self.number.text= dicRecource[@"orderInfo"][@"mobile"];
    _mobileNumber=dicRecource[@"orderInfo"][@"mobile"];
    
self.project.text=dicRecource[@"orderInfo"][@"project"];
    // 价钱
    NSString *price = dicRecource[@"orderInfo"][@"price"];
    self.price.text= [NSString stringWithFormat:@"%@元/%@分钟", price,dicRecource[@"orderInfo"][@"timeLong"]];
    
    self.serverTime.text = [NSString stringWithFormat:@"%@", day_date];
    
    /*服务地址*/
    self.address.text = [NSString stringWithFormat:@"%@", dicRecource[@"orderInfo"][@"address"]];
    
  
    NSString *status =[NSString stringWithFormat:@"%@",dicRecource[@"orderInfo"][@"status"]] ;
    
    if ([status isEqualToString:@"0"]) {
        [self.changeBtn setTitle:@"确认处理" forState:UIControlStateNormal];
    }else if ([status isEqualToString:@"10"]){
        [self.changeBtn setTitle:@"开始服务" forState:UIControlStateNormal];
    }else if ([status isEqualToString:@"20"]){
        [self.changeBtn setTitle:@"服务完成" forState:UIControlStateNormal];
    }
    
    [self.changeBtn addTarget:self action:@selector(btnStatus:) forControlEvents:UIControlEventTouchUpInside];
 _orderId=[NSString stringWithFormat:@"%@",dicRecource[@"orderInfo"][@"orderId"]];
    _status=status;
    
    
}

- (void)btnStatus:(UIButton *)btn{
    
    
    
    if ([_status isEqualToString:@"0"]) {
        //        [btn setTitle:@"确认处理" forState:UIControlStateNormal];
        _status = @"10";
    }else if ([_status isEqualToString:@"10"]){
        //        [btn setTitle:@"开始服务" forState:UIControlStateNormal];
        _status = @"20";
    }else if ([_status isEqualToString:@"20"]){
        //        [btn setTitle:@"服务完成" forState:UIControlStateNormal];
        _status = @"30";
    }
    NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:[[TMCache sharedCache]objectForKey:@"artisanId" ], @"artisanId", _status, @"status", _orderId, @"orderId", nil];
    [[WSNetworkApi shareManager]postWithUrl:@"/order/setOrderStatus" parameters:dictionary option:RequestCenterCachePolicyNormal sucess:^(id responseObject) {
        
        NSLog(@"状态改变%@",responseObject);
        
        if ([responseObject[@"status"] isEqualToString:@"ok"]) {
         
            if (_changeorderStatus) {
                _changeorderStatus();
                
            }
            

        }
        
    } failur:^(NSError *error) {
        
    }];
    

        
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
